package domain.HQLQuery;

import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.util.HashSet;
import java.util.Set;

/**
 * 测试HQL查询用实体
 */
@Entity
@NamedQuery(name = "personNamedQuery",query = "from Person p where p.age > 11")
@Table(name = "person_inf")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class Person {
    @Id
    @Column(name = "person_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    private int age;
    @ManyToMany(targetEntity = MyEvent.class)
    @JoinTable(name = "person_event",
    joinColumns = @JoinColumn(name = "person_id",referencedColumnName = "person_id"),
    inverseJoinColumns = @JoinColumn(name = "event_id",referencedColumnName = "event_id"))
    private Set<MyEvent> myEvents = new HashSet<>();
    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "<Person: "+getName()+", "+getAge()+">";
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Set<MyEvent> getMyEvents() {
        return myEvents;
    }

    public void setMyEvents(Set<MyEvent> myEvents) {
        this.myEvents = myEvents;
    }
}
